#include <iostream>
#include "Sock.hpp"
#include "Protocol.hpp"

using namespace ns_protocol;

static void Usage(const std::string& proc)
{
    std::cout << "\nUsage: " << proc << " serverip serverport\n" << std::endl;
}


// ./client server_ip server_port
int main(int argc, char* argv[])
{
    if (argc != 3)
    {
        Usage(argv[0]);
        exit(1);
    }

    std::string server_ip = argv[1];
    uint16_t server_port = atoi(argv[2]);
    Sock sock;
    int sockfd = sock.Socket();
    if (!(sock.Connect(sockfd, server_ip, server_port)))
    {
        std::cerr << "connect error" << std::endl;
        exit(2);
    }

    while (true)
    {
        Request req(10, 20, '+');
        std::string s = req.Serialize();
        Send(sockfd, s);

        std::string r = Recv(sockfd);
        Response resp;
        resp.Deserialized(r);
        std::cout << "code: " << resp._code << std::endl;
        std::cout << "result: " << resp._result << std::endl;
        sleep(1);
    }


    return 0;
}